package com.zzxy.spring.aspect;

import org.aopalliance.intercept.Joinpoint;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAspectJ {
    @Pointcut(value = "execution(* com.zzxy.spring.service.impl.*.*(..))")
    public void myPointcut(){

    }
    @Before(value = "myPointcut()")
    public void before(JoinPoint joinPoint){
        System.out.println("method name :" + joinPoint.getSignature().getName());
        System.out.println("before ...");
    }
    @After(value = "myPointcut()")
    public void after(){
        System.out.println("after ...");
    }
    @Around(value = "myPointcut()")
    public Object myAround(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("before around ...");
        Object obj = pjp.proceed();
        System.out.println("after around ...");
        return obj;
    }

    @AfterReturning(value = "myPointcut()",returning = "ret")
    public void myAfterReturning(JoinPoint joinPoint,Object ret){
        System.out.println("after returning ..." + ret);
    }
    @AfterThrowing(value = "myPointcut()",throwing = "e")
    public void myAfterReturning(JoinPoint joinPoint,Throwable e){
        System.out.println("after returning ..." + e);
    }
}
